package com.example.bgmachine.bgmachine.popupviews;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.bgmachine.bgmachine.R;
import com.example.bgmachine.bgmachine.commons.CleanStatusRecord;

public class UpReminderView extends Dialog implements
        View.OnClickListener {
    private  Context context;


    /**
     * @Fields dialog_cancel : 按钮
     */
    private Button clean_reminder_view_image_btn_cancel;

    /**
     * @Fields dialog_ok:确定按钮
     */
    private Button clean_reminder_view_image_btn_ok;

    private TextView homepage_popup_dialog_menu_textview = null;

    private TextView homepage_popup_dialog_infor_textview = null;



    private Boolean bool;

    private View.OnClickListener btnOnClick;
    public UpReminderView(Context context) {
        super(context, R.style.SundayDialogs);
        this.context = context;
        bool = true;


        Log.d("aaa", "aaa===2");
        //create();
    }

    @Override
    public void show() {
        super.show();

    }

    /**
     * @param @param btnOnClick
     * @return void
     * @throws
     * @Description: 可以自定义button事件
     * @author Sunday
     */
    public void setBtnOnClick(View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;
        clean_reminder_view_image_btn_ok.setOnClickListener(btnOnClick);
    }

    public void setBtnOkClick(String text,
                              View.OnClickListener btnOnClick) {
        this.btnOnClick = btnOnClick;
        clean_reminder_view_image_btn_ok.setText(text);
        clean_reminder_view_image_btn_ok.setOnClickListener(btnOnClick);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ups_reminder_view_dialog);
        hideBottomUIMenu();
        init();

        Log.d("aaa", "aaa===1");
    }


   private void init() {
       clean_reminder_view_image_btn_cancel = findViewById(R.id.clean_reminder_view_image_btn_cancel);

       clean_reminder_view_image_btn_cancel.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               CleanStatusRecord.getmUrlinfor().setmCleanTopStatus(0);
//               try {
//                  // HomePages.mHomePages.updateCleanReminderView();
//               } catch (ParseException e) {
//                   e.printStackTrace();
//               }
               dismiss();

           }
       });


       clean_reminder_view_image_btn_ok = findViewById(R.id.clean_reminder_view_image_btn_ok);

       homepage_popup_dialog_menu_textview = findViewById(R.id.homepage_popup_dialog_menu_textview);

       homepage_popup_dialog_infor_textview = findViewById(R.id.homepage_popup_dialog_infor_textview);

   }
    /**
     * 隐藏虚拟按键，并且全屏
     */
    protected void hideBottomUIMenu() {
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);


        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window myWindow = this.getWindow();
        myWindow.setFlags(flag, flag);

        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19) {
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);


        }

        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
            }
        });
    }


    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
//        if (isShowing()) {
//            dismiss();
//        }
    }


    public void setMenus( String infors ){

        if(homepage_popup_dialog_menu_textview != null){
            homepage_popup_dialog_menu_textview.setText(infors);
        }
    }
    public void setInfors( String infors ){

        if(homepage_popup_dialog_infor_textview != null){
            homepage_popup_dialog_infor_textview.setText(infors);
        }
    }

}
